<template>
	<view>
		<span v-show="mainflag" class="container ">
			<div v-show="!showflag" class="flex-center flex-column" style="height: 800rpx;">
				<image src="/static/erro/nodata.png" style="width: 200rpx;height: 200rpx;"></image>
				<text class="font-color-999">暂无报修消息...下拉刷新</text>
			</div>
			<!-- <no-info v-show="!showflag"></no-info> -->
			<span v-show="showflag" style="width: 100%;height: 100%;background-color: #FFFFFF;">
				<view class="item border-bottom flex-row align-items-center flex-space-between" v-for="(item,key) in info" :key="key" @click="push(item.id)">
					<view class="img-box">
						<image :src=" item.equipment_file" class="my-img "></image>
					</view>
					<view class="content-box  ">
						<view class="content-one flex-row font-14px ">
							<text class="left lin-hid">客户公司：{{item.user_dep}}</text>
							<text class="right" :style="{color:status[(item.status?item.status:0)].color}">{{status[(item.status?item.status:0)].value}}</text>
						</view>
						<view class="content-two font-color-999">
							地址：{{item.user_address}}
						</view>
						<view class="content-three font-color-999 flex-space-between">
							<text class="lin-hid">设备机身号：{{item.number}}</text>
							<text class="lin-hid">提交时间：{{item.createTime.slice(0,10)}}</text>
						</view>
					</view>
				</view>
				<uni-pagination  style=" z-index: 999; position: fixed; bottom: 20rpx;width: 100%;" :current="page" title="标题文字" :total="total" :pageSize="limit" @change="change"></uni-pagination>
			</span>
		</span>
	</view>
</template>

<script>
	import uniPagination from '@/components/uni-pagination/uni-pagination.vue'
	import permission from '@/utils/permission.js'
	import {getRepairByEngineerIdList,getRepairList} from '@/api/user/index.js'
	export default {
		components: {uniPagination},
		data() {
			return {
				mainflag: false,
				showflag: false,
				page:1,
				limit:10,
				total:0,
				status:[
					{
						id:0,
						value:'待处理',
						color:'#ff5500'
					},{
						id:1,
						value:'已处理',
						color:'#00ff7f'
					},{
						id:2,
						value:'待处理',
						color:'#ff5500'
					},
				],
				info: [{
					id:'',
					file:[{
						id:"",
						repair_id:'',
						file: "",
					}] ,
					applicant: '',
					phone: '',
					state: '',
					status:'',
					equipment_id: '',
					content:'',
					createTime:'',
				}],
				defaultImg: '/static/erro/defaultImg.png'


			}
		},
		methods: {
			push(id){
				uni.navigateTo({
				    url: '/pages/views/engineer/MessageDetails/MessageDetails?id='+id
				});
			},
			getRepairList(){
				let job = this.$store.getters.job
				if(job === '高级工程师'){
					getRepairList(this.limit,this.page).then(res =>{
						if(res.result.data.length > 0){
								this.total = res.result.limitCount
								this.info = res.result.data
								this.info.forEach((item)=>{
									let defaultfile = [{
										file: this.defaultImg,
									}] 
									if(item.file.length == 0 || item.file[0].file == ''){
										item.file = defaultfile
									}
								})
								console.log("数据")
								console.log(this.info)
								uni.hideLoading()
								this.mainflag = true
								this.showflag = true
							}else{
								this.showflag = false
								uni.hideLoading()
								this.mainflag = true
							}
					})
				}else{
					let id = this.$store.getters.id
					getRepairByEngineerIdList(id,this.limit,this.page).then((res)=>{
						if(res.result.data.length > 0){
							this.total = res.result.limitCount
							this.info = res.result.data
							this.info.forEach((item)=>{
								let defaultfile = [{
									file: this.defaultImg,
								}] 
								if(item.file.length == 0 || item.file[0].file == ''){
									item.file = defaultfile
								}
							})
							console.log("数据")
							console.log(this.info)
							uni.hideLoading()
							this.mainflag = true
							this.showflag = true
						}else{
							this.showflag = false
							uni.hideLoading()
							this.mainflag = true
						}
						
					})
				}
				
			},
			/**
			 * 分页上一页下一页事件
			 * 
			 */
			change(type,current){
				this.page = type.current
				this.getRepairList()
			}
		},
		onShow() {
			/**
			 * 检验当前是否已经登录
			 */
			let curRoute  = this.$mp.page.route;
			this.$intercept.permission(curRoute)
		},
		onLoad() {
			uni.startPullDownRefresh();
			this.getRepairList()
		},
		onPullDownRefresh() {
			this.getRepairList()
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100%;

		.item {
			width: 90%;
			height: 178rpx;
			margin: 0 auto;
			.content-box {
				height: 132rpx;
				width: 75%;

				.content-one {
					color:#ec8b89;
					height: 36.33%;
					width: 100%;
					.left {
						width: 70%;
						
					}

					.right {
						width: 30%;
						text-align: right;
					}
				}

				.content-two {
					font-size: 26rpx;
					height: 31.33%;
					line-height: 41.35rpx;
				}

				.content-three {
					font-size: 20rpx;
					height: 31.33%;
					line-height: 41.35rpx;
				}
			}

			.img-box {
				height: 132rpx;
				width: 20%;
			}
		}

	}
	
</style>
